package com.twu.bibilioteca;

import java.nio.file.LinkOption;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: dixithk
 * Date: 6/12/14
 * Time: 5:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class Library {

    public  ArrayList<Book> books = new ArrayList<Book>();
    public  ArrayList<Movie> movies = new ArrayList<Movie>();
    public ArrayList<User>  users = new ArrayList<User>();
    

    public void addBook(Book book)
    {
          books.add(book);
    }
    
    public void addUser(User user)
    {
        users.add(user);
    }


    public Book GiveBookObjectFromTitle(String BookQueryTitle ) {



        for (Book book : books) {
            if ((book.getTitle()).equals(BookQueryTitle)) {

                return book;
            }

        }

        return null;

    }

    public Movie GiveMovieObjectFromTitle(String MovieQueryTitle ) {



        for (Movie movie :movies) {
            if ((movie.getName()).equals(MovieQueryTitle)) {

                return movie;
            }

        }

        return null;

    }


    public  boolean isBookAvailableForCheckOut(Book book)
    {
       return book.isCheckedOut();
    }

    public  boolean isMovieAvailableForCheckOut(Movie movie)
    {
        return movie.isCheckedOut();
    }

    public  boolean isValidReturn(Book bookNeedToBeReturned) {
            
        return bookNeedToBeReturned.isCheckedOut();
    }


    public void loadBooks()
    {
        books.add(new Book("program in C" , "subbu" , 1998 , false));
        books.add(new Book("program in java" , "subbu" , 1998 , false));
        books.add(new Book("program in python" , "subbu" , 1998, false));
        books.add(new Book("program in Ruby" , "subbu" , 1998, false));
        books.add(new Book("program in scala" , "subbu" , 1998, false));
    }

    public  ArrayList<Book> getBooks()
    {
        ArrayList<Book> availableBooks = new ArrayList<Book>();
        for(Book book :books)
        {
            if(!book.isCheckedOut())
            {
                availableBooks.add(book);
            }
        }
        return availableBooks;

    }

    public ArrayList<Movie> getMovies()
    {

        ArrayList<Movie> availableMovies= new ArrayList<Movie>();
        for(Movie movie :movies)
        {
            if(!movie.isCheckedOut())
            {
                availableMovies.add(movie);
            }
        }
        return availableMovies;

    }

    public void addMovie(Movie movie)
    {
          movies.add(movie)  ;
    }


    public void loadMovies()
    {
            movies.add(new Movie("22 Jump Street" , "Phil Lord" , 2014 ,8))  ;
        movies.add(new Movie("How to train a dragon" , "Dean De" , 2014 ,8))  ;
        movies.add(new Movie("Maleficent" , "Robert" , 2014 ,7))  ;
        movies.add(new Movie("3 idiots" , "irani" , 2011 ,10))  ;
        movies.add(new Movie("manam" , "vikarm" , 2014 ,9))  ;


    }
    
    public void loadUsers()
    {
          users.add(new User("dixith" , "dixithk@thoughtworks.com" , "305-3051" ,"password" , "8179977996"));
        users.add(new User("aswathi" , "aswathik@tw.com" , "304-3041" , "password" , "8179977996"));
        users.add(new User("sahelij" ,"sahelig@tw.com" , "331-331" , "password" , "8176666560"));
        users.add(new User("padma" , "padmab@tw.com", "303-303" , "password" , "8777777444"));
        users.add(new User("sravathi" ,"ns@tw.com" , "336-3361" , "password" , "12345678"));

    }

    public User getUser(String QueryLogin) {
        for(User u : users)
        {            if(u.getLogin().equals(QueryLogin))
            {
              return u;
            }
        }
        return null;
    }
}
